import BaseListApp from '@/lib/base/BaseListApp';
import { WEBS, PAGES } from '@/lib/core/Apicloud';

export default {
    // TabLayout 头部背景颜色
    HEADER_BG_COLOR: '#fff',
    // TabLayout 头部标题颜色
    HEADER_COLOR: '#333',
    // TabLayout头部高度
    HEADER_HEIGHT: 44,
    // TabLayout头部标题是否加粗
    HEADER_WEIGHT: true,
    // TabLayout 返回按钮深色图标
    HEADER_BACK_BUTON_DARK_ICON: require('@/assets/images/header_back_btn_icon_dark.png'),
    // TabLayout 返回按钮浅色图标
    HEADER_BACK_BUTON_LIGHT_ICON: require('@/assets/images/header_back_btn_icon_light.png'),
    //H5 TabLayout 关闭按钮深色图标
    HEADER_CLOSE_BUTON_DARK_ICON: require('@/assets/images/close_black.png'),
    //H5 TabLayout 关闭按钮浅色图标
    HEADER_CLOSE_BUTON_LIGHT_ICON: require('@/assets/images/close_white.png'),
    // 列表加载数据成功后公共格式化函数
    LIST_VIEW_REQUEST_FORMAT_DATA(app: BaseListApp, res: any) {
        const pagination = app.getPagination();
        let loadAll = false;
        if (res.code === 200) {
            const list = res.data || [];
            if (pagination.page === 1) {
                app.getList().splice(0, app.getList().length, ...list);
            } else {
                app.getList().push(...list);
            }

            if (list.length >= app.getMinPageSize()) {
                app.setPage(pagination.page + 1);
            } else {
                loadAll = true;
            }
        } else {
            // 只在第一页清空
            if (pagination.page === 1) {
                app.getList().splice(0, app.getList().length);
            }
            app.setLoadFail(true);
        }
        if (!app.isRefreshed()) {
            app.refreshHeaderLoadDone();
        }
        app.$nextTick(() => {
            app.setLoad(true);
            app.setLoadAll(loadAll);

        });
    },
    // BaseListApp 默认空组件
    LIST_VIEW_EMPTY_VIEW(app: BaseListApp) {
        // 是否加载失败
        const isLoadFail = app.isLoadFail();
        // 没有数据时空组件显示的文字
        const emptyDataText = app.getEmptyDataText();
        // 没有数据时空组件按钮显示的文字
        const emptyDataBtnText = app.getEmptyDataBtnText();
        // 没有数据时空组件按钮点击的回调
        const callback = app.getEmptyDataBtnCallback();
        return 'empty';
    },
    // BaseListApp 默认加载中组件
    LIST_VIEW_LOADING_VIEW(app: BaseListApp) {
        return 'loading';
    },
    // BaseListApp 默认 加载更多组件
    LIST_VIEW_LOAD_MORE_VIEW(app: BaseListApp) {
        return 'loadMore';
    },
    // 下拉刷新默认头部
    REFRESH_HEADER: {
        // 下拉过程显示图片索引
        defaultIndex: 0,
        // 下拉刷新中帧动画图片组成 
        load: [
            require('@/assets/images/refresh/refresh_1.png'),
            require('@/assets/images/refresh/refresh_2.png'),
            require('@/assets/images/refresh/refresh_3.png'),
            require('@/assets/images/refresh/refresh_4.png'),
            require('@/assets/images/refresh/refresh_5.png'),
            require('@/assets/images/refresh/refresh_6.png'),
            require('@/assets/images/refresh/refresh_7.png'),
            require('@/assets/images/refresh/refresh_8.png'),
        ],
        // 下拉刷新中帧动画播放速度，单位s
        animationStep: 70
    },
    // 打开新窗口拦截函数
    async OPEN_WIN_INTERCEPTORS<T extends keyof PAGES, W extends keyof WEBS>(name: T | W, config: OpenWinParams) {

        return true;
    }
}
